<template>
  <div>
      <router-link v-show="show" tag="div" to="/" class="header-abs icon iconfont icon-back"></router-link>
      <div class="header-fixed" v-show="!show" :style="opacityStyle">
        <router-link to="/">
          <div class="header-left icon iconfont icon-back"></div>
        </router-link>
        <div class="header-input">景点详情</div>
      </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      show: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.show = false
      } else {
        this.show = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style scoped>
.header-abs{
  position: absolute;
  top: 10px;
  left: 10px;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background:black;
  line-height: 40px;
  color: #fff;
  text-align: center;
  font-size: 20px;
  z-index: 2
}
.header-fixed{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  line-height:43px;
  overflow: hidden;
  background: #00bcd4;
  color: #fff
}
.header-input,.header-left{
  float: left;
}
.header-left{
  width: 15%;
  text-align: center;
  font-size: 26px;
  color: #fff
}
.header-input{
  width:75%;
  line-height: 33px;
  margin-top: 5px;
  text-align: center
}
</style>
